
numbers = [5, 12, 27, 10, 0, -5, 27]

# 数组里有几个元素?
answer = len(numbers)
print(answer)

# 数组里第1个元素是什么？
answer = numbers[0]
print(answer)

# 数组里第2个元素是什么？
answer = numbers[1]
print(answer)

# 数组里最后一个元素是什么？
answer = numbers[-1]
print(answer)

# 数组所有元素之和是多少？

# 方法一 使用下标
def sum_all_1(list_of_nums):
    total = 0
    for i in range(len(list_of_nums)):
        total += list_of_nums[i]
    return total

# 方法二 使用元素
def sum_all_2(list_of_nums):
    total = 0
    for x in list_of_nums:
        total += x
    return total

# 使用方法一
answer = sum_all_1(numbers)
print(answer)
# 使用方法二
answer = sum_all_2(numbers)
print(answer)